package com.ynu.znkz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ynu.znkz.entity.PaperResearchMethod;
import com.ynu.znkz.entity.PaperResearchObj;
import com.ynu.znkz.mapper.PaperResearchMethodMapper;
import com.ynu.znkz.service.PaperResearchMethodService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lu
 * @since 2021-05-29
 */
@Service
public class PaperResearchMethodServiceImpl extends ServiceImpl<PaperResearchMethodMapper, PaperResearchMethod> implements PaperResearchMethodService {


    @Override
    public String savePaperResearchMethod(String paperResearchMethodName) {
        QueryWrapper<PaperResearchMethod> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",paperResearchMethodName);
        List<PaperResearchMethod> paperResearchMethods = baseMapper.selectList(queryWrapper);

        //研究方法数据库中没有当前研究方法
        if(paperResearchMethods.isEmpty()) {
            PaperResearchMethod paperResearchMethod = new PaperResearchMethod();
            paperResearchMethod.setName(paperResearchMethodName);
            baseMapper.insert(paperResearchMethod);
            return paperResearchMethod.getId();
        }else
            return paperResearchMethods.get(0).getId();
    }
}
